// const clock = require("@/api/clock/clock.js");
// const index = require('@/api/index/index.js')
export default {
	data() {
		return {
			// 默认的全局分享内容
			share: {
				title: '太行羿文体教培',
				path: '',
				imageUrl: '',
				// https://niule.qfycloud.com/images/icons13.png
			},
			info: {
				nickName: uni.getStorageSync('nickName'),
				avatarUrl: uni.getStorageSync('avatarUrl')
			},
			navInfo: {
				statusBarHeight: 0, // 状态栏高度
				navBarHeight: 0, // 导航栏高度
				safeAreaHeight: 0, // 底部安全区域高度
				menuRight: 0, // 胶囊右侧间隙大小
				menuTop: 0, // 胶囊顶部间隙大小
				menuBottom: 0, // 胶囊底部间隙大小
				menuHeight: 0, // 胶囊高度
				menuWidth: 0, // 胶囊宽度
			}
		}
	},
	created() {
		// 获取系统信息
		const {
			statusBarHeight,
			screenWidth,
			screenHeight,
			safeArea
		} = uni.getSystemInfoSync();
		// #ifdef MP-WEIXIN
		// 胶囊按钮位置信息
		const {
			top,
			right,
			height,
			width
		} = uni.getMenuButtonBoundingClientRect();
		this.navInfo.navBarHeight = (top - statusBarHeight) * 3 + height + statusBarHeight;
		this.navInfo.menuRight = screenWidth - right;
		this.navInfo.menuTop = top;
		this.navInfo.menuBottom = (top - statusBarHeight) * 2;
		this.navInfo.menuHeight = height;
		this.navInfo.menuWidth = width;
		// #endif
		this.navInfo.statusBarHeight = statusBarHeight;
		this.navInfo.safeAreaHeight = screenHeight - safeArea.bottom;
	},
	methods: {
		refreshUserInfo(value) {
			index.getUserInfo().then(res => {
				if (res.data.code == 200) {
					uni.setStorageSync('userInfo', res.data.data)
					if (value && uni.getStorageSync('currentTeam') && uni.getStorageSync('currentTeam').id) {
						clock.memberinfo({
							memberId: res.data.data.id,
							teamId: uni.getStorageSync('currentTeam').id
						}).then(res => {
							if (res.data.code == 200) {
								uni.setStorageSync('mmember', res.data.data.member)
							}
						})
					}
				}
			})
		},
		// 根据id获取 图片/视频/音频
		getMedia(id) {
			return 'https://shop-wx.nulemedical.com/file/mp/download?id=' + id + '&token=' + uni.getStorageSync('token')
		},
		async uploadFiles(filePath, name = 'file') {
			return await uni.uploadFile({
				url: 'https://shop-wx.nulemedical.com/file/mp/uploadLocalReturnId',
				filePath,
				name,
				header: {
					token: uni.getStorageSync("token")
				},
				success: (res) => {
					if ((JSON.parse(res.data)).code == 200) {
						return (JSON.parse(res.data))
					}
				}
			})
		},
		// 时间格式化
		formatDate(date = new Date(), format = 'YYYY-MM-DD hh:mm:ss') {
			if (!(date instanceof Date)) {
				date = new Date(date);
			}
			const YYYY = date.getFullYear();
			const MM = ('0' + (date.getMonth() + 1)).slice(-2);
			const DD = ('0' + date.getDate()).slice(-2);
			const hh = ('0' + date.getHours()).slice(-2);
			const mm = ('0' + date.getMinutes()).slice(-2);
			const ss = ('0' + date.getSeconds()).slice(-2);

			const result = format
				.replace(/YYYY/, YYYY)
				.replace(/MM/, MM)
				.replace(/DD/, DD)
				.replace(/hh/, hh)
				.replace(/mm/, mm)
				.replace(/ss/, ss);
			return result;
		}
	},
	onShareAppMessage(res) {
		return {
			title: '太行羿文体教培',
			path: this.share.path,
			imageUrl: this.share.imageUrl,
		}
	},
	//2.分享到朋友圈
	onShareTimeline(res) {
		return {
			title: '太行羿文体教培',
			path: this.share.path,
			imageUrl: this.share.imageUrl,
		}
	},
}